package com.cykj.util;
import java.security.MessageDigest;

/**
 * @BelongsProject: 12306-project
 * @BelongsPackage: com.cykj.util
 * @Author: 小林
 * @CreateTime: 2024-12-03 19:47
 * @Description: MD5加密工具类
 * @Version: 1.0
 */
public class MD5Util {
    public static String encrypt(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] byteArray = md.digest(str.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder();
            for (byte b : byteArray) {
                sb.append(String.format("%02x", b)); // 转换为16进制
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException("MD5加密出错", e);
        }
    }
}

